#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i(a);i<=(b);++i)
#define req(i,a,b) for(int i(a);i>=(b);--i)
#define sort stable_sort
using namespace std;
char buf[1<<23],*p1=buf,*p2=buf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<23,stdin),p1==p2)?EOF:*p1++)
template<typename TP> inline TP read(TP &num)
{
	TP x=0;
	int f=0;
	char ch=getchar();
	while(ch<48||ch>57) f|=ch=='-',ch=getchar();
	while(48<=ch&&ch<=57) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return num=f?-x:x;
}
template<typename ...Args> inline void read(Args &...args)
{
	(read(args),...);
}
template<typename TP> inline void write(TP x)
{
	(x<0)?(putchar('-'),x=-x):0;
	(x>9)?(write(x/10),0):0;
	putchar((x%10)^48);
}
template<typename TP> inline void writeln(TP x)
{
	write<TP>(x);
	puts("");
}
signed main()
{
	freopen("game.in","r",stdin);
	freopen("game.out","w",stdout);
	int n; read(n);
	vector<pair<int,int>> c(n);
	for(auto &[x,y]:c) read(x,y);
	if(n<=4000)
	{
		int minx=1e18,miny=1e18;
		for(auto [x,y]:c) minx=min(minx,x),miny=min(miny,y);
		vector<vector<int>> id(n+1,vector<int>(n+1,n));
		rep(i,0,n-1)
		{
			auto &[x,y]=c[i];
			x-=minx,y-=miny,id[x][y]=i;
		}
		int ans=0;
		rep(i,0,n-1)
		{
			auto [sx,sy]=c[i];
			queue<pair<int,int>> q;
			q.emplace(sx,sy);
			vector<int> dis(n+1,-1); dis[i]=dis[n]=0;
			while(!q.empty())
			{
				auto [x,y]=q.front(); q.pop();
				if(x>0&&dis[id[x-1][y]]==-1) dis[id[x-1][y]]=dis[id[x][y]]+1,q.emplace(x-1,y);
				if(y>0&&dis[id[x][y-1]]==-1) dis[id[x][y-1]]=dis[id[x][y]]+1,q.emplace(x,y-1);
				if(x<n&&dis[id[x+1][y]]==-1) dis[id[x+1][y]]=dis[id[x][y]]+1,q.emplace(x+1,y);
				if(y<n&&dis[id[x][y+1]]==-1) dis[id[x][y+1]]=dis[id[x][y]]+1,q.emplace(x,y+1);
			}
			rep(j,0,n-1) ans+=dis[j];
		}
		writeln(ans/2),exit(0);
	}
	int minx=1e18,miny=1e18,maxx=0,maxy=0;
	for(auto [x,y]:c) minx=min(minx,x),miny=min(miny,y),maxx=max(maxx,x),maxy=max(maxy,y);
	auto rect_val=[&](int x1,int y1,int x2,int y2)->int
	{
		int lx=x2-x1+1,ly=y2-y1+1;
		return lx*ly*(lx+ly-2)/2;
	};
	auto ls=[&](int l,int r)->int{r-=l-1,l=1;return (l+r)*(r-l+1)/2;};
	int ans=0;
	rep(i,minx,maxx) rep(j,miny,maxy)
	{
		// left-up rect of (i,j)
		int lu=rect_val(minx,miny,i,j);
		int ru=rect_val(i,miny,maxx,j);
		int ld=rect_val(minx,j,i,maxy);
		int rd=rect_val(i,j,maxx,maxy);
		ans+=lu+ru+ld+rd-ls(minx,i-1)-ls(i+1,maxx)-ls(miny,j-1)-ls(j+1,maxy);
	}
	writeln(ans/2);
	return 0;
}
